package com.tianyu.inspection.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.tianyu.inspection.common.Constants;
import com.tianyu.inspection.common.enums.Role;
import com.tianyu.inspection.common.annotation.Permission;
import com.tianyu.inspection.common.component.Validate;
import com.tianyu.inspection.entity.GeneralFacilities;
import com.tianyu.inspection.entity.GeneralFacilitiesType;
import com.tianyu.inspection.entity.model.QueryMo;
import com.tianyu.inspection.entity.vo.Ro;
import com.tianyu.inspection.service.api.IGeneralFacilitiesService;
import com.tianyu.inspection.service.api.IGeneralFacilitiesTypeService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

/**********************************
 * @Author YSW
 * @Description 日志打印接口
 * @Date 2021/7/29 - 10:47
 **********************************/

@RestController
@RequestMapping("/api/2.0")
@Slf4j
public class OtherController {


    @Resource
    private IGeneralFacilitiesService valueChestService;

    @Resource
    private IGeneralFacilitiesTypeService generalFacilitiesTypeService;

    @Resource
    private Validate validateModel;

    @GetMapping(value = "/valueChest/list")
    @Permission(value = 4,tags = Constants.API_PATROL)
    public Ro<IPage<GeneralFacilities>> getPageList(HttpServletRequest request, @RequestHeader("u-projectId") Integer projectId){
        QueryMo queryMo = QueryMo.getQueryMo(request);
        Ro<IPage<GeneralFacilities>> ro = new Ro<>();
        queryMo.build(GeneralFacilities.class,projectId);
        return ro.setContent(valueChestService.searchListPage(queryMo));
    }

    @GetMapping(value = "/valueChestType/list")
    @Permission(value = 4,tags = Constants.API_PATROL)
    public Ro<Object> getValueChestTypePageList(HttpServletRequest request, @RequestHeader("u-projectId") Integer projectId){
        QueryMo queryMo = QueryMo.getQueryMo(request);
        int roleId = (int) request.getAttribute("roleId");
        Ro<Object> ro = new Ro<>();
        queryMo.build(GeneralFacilitiesType.class,null);
        if (roleId == Role.ROLE_SUPER_ADMIN.getValue()) {
            return ro.setContent(generalFacilitiesTypeService.searchListPage(queryMo));
        }else {
            return ro.setContent(generalFacilitiesTypeService.searchList(queryMo,projectId));
        }
    }
}
